<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="author" content="常伟">
    <title>知识问答</title>
    <link rel="stylesheet" href="/css/main.css">
</head>

<body>
    <h1>知识问答</h1>
    {{if user}} {{user.account}}
    <a href="/user/signout">退出</a> {{else}}
    <a href="/user/signin">登录</a>
    <a href="/user/register">注册</a> {{/if}}
    <div>
        <a href="/ask">添加问题</a>
    </div>
    <hr>
    <ul>
        {{each keywords as kw i}}
        <li class="{{ keyword == kw.text ? 'selected' : ''}}">
            <a href="/k-{{kw.text}}">{{kw.text}}</a>
        </li>
        {{/each}}
    </ul>
    <hr> {{each questions as q i}}
    <section qid="{{q.id}}">
        <h3>
            {{q.text}} {{if user && (user.id == q.createUser._id || user.account == 'admin')}}
            <a href="javascript:removeQuestion('{{q.id}}')">删除</a> {{/if}}
        </h3>
        <p>{{q.keyword}}，{{q.createUser.account}}， {{q.createTime | formatTime}}，{{q.ip}}</p>
        {{each q.answers as a i}}
        <section aid="{{a._id.toString()}}">
            <h4>
                {{a.text}} {{if user && (user.id == a.createUser._id || user.account == 'admin')}}
                <a href="javascript:removeAnswer('{{a._id.toString()}}')">删除</a> {{/if}}
            </h4>
            <p>{{a.createUser.account}}, {{a.createTime | formatTime}}, {{a.ip}}</p>
        </section>
        {{/each}}
        <section><a href="/answer/{{q.id}}">回答</a></section>
    </section>
    {{/each}}

    <script src="/libs/jquery.js"></script>
    <script src="/js/index.js"></script>
</body>

</html>